<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="renderer" content="webkit">
		<link href="../../css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="../../js/jquery-easyui-1.4.4/themes/bootstrap/easyui.css">
		<link rel="stylesheet" href="../../js/jquery-easyui-1.4.4/themes/icon.css">
		<link rel="stylesheet" href="../../css/ext_icon.css">
		<script src="../../js/jquery-easyui-1.4.4/jquery.min.js"></script>
		<script src="../../js/bootstrap.min.js"></script>
		<script src="../../js/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
		<script src="../../js/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
		<script src="../../js/ext_jquery.js"></script>
		<script src="../../js/ext_easyui.js"></script>
		<script src="../../js/jquery.form.js"></script>
		<script src="../../js/My97DatePicker/WdatePicker.js"></script>
		<script src="../../js/Chart.min.js"></script>
		<script src="../../js/util.js"></script>
		<script src="../../js/ckeditor/ckeditor.js"></script>
		<link rel="stylesheet" href="../../css/style.css">
		<script src="../../js/main.js"></script>
		<script src="../../js/sha1.js"></script>
		<script src="../../js/upfile.js"></script>
		<title></title>
	</head>

	<body>
		<script>
			$(function() {
				var submitForm = $('.form-table');
				var options = {
					dataType: 'json',
					beforeSubmit: function() {
						if (!submitForm.form('enableValidation').form('validate')) {
							parent.$.messager.progress('close');
							return false;
						}
						parent.$.messager.progress({
							title: '提示',
							text: '数据保存中，请稍后....'
						});
						return true;
					},
					success: function(result) {
						parent.$.messager.progress('close');
						if (result.success) {
							parent.$.messager.show({
								title: '提示',
								msg: '新增成功!',
								timeout: 3000
							});
							parent.$.modalDialog.openner_dataGrid
								.datagrid('reload'); //刷新表格
							parent.$.modalDialog.handler.dialog('close');
							//removeTabs();
						} else {
							parent.$.messager.alert('错误', result.msg, 'error');
						}
					}
				};
				submitForm.bind('submit', function(e) {
					e.preventDefault(); // <-- important
					$(this).ajaxSubmit(options);
				});
				$('#fff').next().children('#filebox_file_id_1').attr('onchange', 'file(event)');
			});

			function submitForm() {
				//$('.form-table').submit();
				parent.$.messager.progress({
					title: '提示',
					text: '数据保存中，请稍后....'
				});
				setTimeout(function() {
					parent.$.messager.progress('close');
					parent.$.messager.show({
						title: '提示',
						msg: '添加成功!',
						timeout: 3000
					});
					removeTabs();
				}, 1200);
			}

			var uploader = uploadJSSDK;
			var image, name;

			function file(e) {
				for (var i = 0; i < e.target.files.length; i++) {
					image = e.target.files[i];
				}
			}

			function upload() {
				$.ajax({
					type: 'POST',
					url: 'http://192.168.1.190:88/weixin/a',
					dataType: 'json',
					timeout: 2700,
					data: {
						'type': 0
					},
					success: function(res) {
						if (0 == res.STATE) {
							name = (new Date()).getTime() + image.name;
							uploader({
								file: image, //文件，必填,html5 file类型，不需要读数据流，
								name: name, //文件名称，选填，默认为文件名称
								token: res.RESULT.msg, //token，必填
								dir: '/ttt', //目录，选填，默认根目录''
								retries: 0, //重试次数，选填，默认0不重试
								maxSize: 0, //上传大小限制，选填，默认0没有限制
								callback: function(percent, result) {
									//percent（上传百分比）：-1失败；0-100上传的百分比；100即完成上传
									//result(服务端返回的responseText，json格式)
									if (100 == percent && 'OK' == result.code && 'OK' == result.message) {
										if (result.isImage) {
											alert(result.url);
										} else {
											del();
											alert('上传的不是图片，请重新选择');
										}
									} else {
										alert('图片上传失败，请重新提交');
									}
								}
							});
						}
					},
					error: function(XMLHttpRequest, errorThrow) {
						//alert(XMLHttpRequest.status);
						//alert(XMLHttpRequest.readyState);
						alert(errorThrow);
					},
					complete: function(XMLHttpRequest, textStatus) {}
				});
			}

			function del() {
				$.ajax({
					type: 'POST',
					url: 'http://192.168.1.190:88/weixin/a',
					dataType: 'json',
					timeout: 2700,
					data: {
						'dir': '/ttt',
						'name': name
					},
					success: function(res) {},
					error: function(XMLHttpRequest, errorThrow) {
						//alert(XMLHttpRequest.status);
						//alert(XMLHttpRequest.readyState);
						alert(errorThrow);
					},
					complete: function(XMLHttpRequest, textStatus) {}
				});
			}

			function api_db() {
				var now = new Date();
				var appKey = hex_sha1('A6916515772039' + 'UZ' + 'DEBDA07D-B91A-DB76-EB41-7D4503464688' + 'UZ' + now.getTime()) + '.' + now.getTime();
				$.ajax({
					'url': 'https://d.apicloud.com/mcm/api/image',
					'method': 'POST',
					'cache': false,
					'headers': {
						'X-APICloud-AppId': 'A6916515772039',
						'X-APICloud-AppKey': appKey
					},
					'data': {
						'path': $('#fff').val(),
					}
				}).success(function(data, status, header) {
					alert('s');
					alert(JSON.stringify(data));
					alert(JSON.stringify(status));
					alert(JSON.stringify(header));
				}).fail(function(header, status, errorThrown) {
					alert(JSON.stringify(errorThrown));
				});
			}
		</script>
		<form class="form-table" style="width: 90%;" action="" method="post">
			<table class="table table-bordered table-condensed">
				<tr>
					<th width="20%">营业执照注册号：</th>
					<td colspan="3"><input class="easyui-textbox" name="name" data-options="prompt:'输入营业执照注册号',required:true" style="width: 100%; height: 30px;"></td>
				</tr>
				<tr>
					<th>公司名称：</th>
					<td colspan="3"><input class="easyui-textbox" name="name" data-options="prompt:'输入公司名称',required:true" style="width: 100%; height: 30px;"></td>
				</tr>
				<tr>
					<th>法人代表：</th>
					<td width="30%"><input class="easyui-textbox" name="d" data-options="prompt:'输入法人代表',required:true,validType:'CHS'" style="width: 100%; height: 30px;"></td>
					<th width="20%">固定电话：</th>
					<td width="30%"><input class="easyui-textbox" name="d" data-options="prompt:'输入固定电话'" style="width: 100%; height: 30px;"></td>
				</tr>
				<tr>
					<th>公司地址：</th>
					<td colspan="3"><input class="easyui-textbox" name="add" data-options="prompt:'输入公司地址',required:true" style="width: 100%; height: 30px;"></td>
				</tr>
				<tr>
					<th>成立日期：</th>
					<td>
						<input class="easyui-datebox" data-options="
								sharedCalendar:'#cc',editable:false,
								icons: [{
									iconCls:'icon-clear',
									handler: function(e){
										$(e.data.target).textbox('clear');
										}
									}]" style="width: 100%;height: 30px;"></td>
					<th>营业期限：</th>
					<td width="30%">自
						<input class="easyui-datebox" data-options="
								sharedCalendar:'#cc',editable:false,
								icons: [{
									iconCls:'icon-clear',
									handler: function(e){
										$(e.data.target).textbox('clear');
										}
									}]" style="width: 90%;height: 30px;"><br>至
						<input class="easyui-datebox" data-options="
								sharedCalendar:'#cc',editable:false,
								icons: [{
									iconCls:'icon-clear',
									handler: function(e){
										$(e.data.target).textbox('clear');
										}
									}]" style="width: 90%;height: 30px;"></td>
				</tr>
				<tr>
					<th>营业执照：</th>
					<td colspan="3"><input id="fff" class="easyui-filebox" data-options="required:true,
								prompt:'上传营业执照的相片',
								buttonText:'选择上传'" style="width: 100%;height: 30px;"></td>
				</tr>
				<tr>
					<th>联系人：</th>
					<td><input class="easyui-textbox" name="d" data-options="prompt:'输入联系人',required:true,validType:'CHS'" style="width: 100%; height: 30px;"></td>
					<th>联系电话：</th>
					<td><input class="easyui-numberbox" name="d" data-options="prompt:'输入联系电话',required:true,validType:'mobile'" style="width: 100%; height: 30px;"></td>
				</tr>
				<tr>
					<th>邮箱：</th>
					<td colspan="3"><input class="easyui-textbox" name="add" data-options="prompt:'输入邮箱',required:true" style="width: 100%; height: 30px;"></td>
				</tr>
				<tr>
					<th>备注：</th>
					<td colspan="3"><textarea name="description" class="form-control" rows="3"></textarea></td>
				</tr>
			</table>
		</form>
		<div style="text-align: center;padding-bottom: 10px;">
			<a href="javascript:void(0);" class="btn btn-primary" role="button" onclick="submitForm();return false;">提&nbsp;&nbsp;&nbsp;&nbsp;交</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="javascript:void(0);" class="btn btn-primary" role="button" onclick="removeTabs();">返&nbsp;&nbsp;&nbsp;&nbsp;回</a>
		</div>
		<div id="cc" class="easyui-calendar"></div>
	</body>

</html>